//
//  RMMGoodsEvaluationView.m
//  Romomo
//
//  Created by puman on 2016/10/26.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMGoodsEvaluationView.h"

@implementation RMMGoodsEvaluationView
{
    UILabel *_scoreLabel;
    UILabel *_label;
}
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        CGFloat width = (kScreenWideth - 110) / 2;
        for (int i = 0; i < 2; i++) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(15 + (width + 80) * i, kRow, width, 0.5)];
            view.backgroundColor = COLORFROMCODE(0xEEEEEE, 1);
            [self addSubview:view];
            if (i == 0) {
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(view.right, 0, 80, kMaric)];
                label.font = kFont(14);
                label.textAlignment = NSTextAlignmentCenter;
                label.textColor = COLORFROMCODE(0xB5B5B5, 1);
                label.text = @"评价技师";
                _label = label;
                [self addSubview:label];
            }
        }
        for (int i = 0; i < 5; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((self.width - 40 - 125) / 2  + 35 * i, kMaric + kRow, 25, 25)];
            imageView.image = [UIImage imageNamed:@"星1-2@3x"];
            imageView.tag = 20 +i;
            [self addSubview:imageView];
            if (i == 4) {
                _scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageView.right + 5, imageView.top + kRow, kHalf, 15)];
                _scoreLabel.font = kFont(12);
                _scoreLabel.textColor = COLORFROMCODE(0xB5B5B5, 1);
                [self addSubview:_scoreLabel];
            }
        }

    }
    return self;
}
- (void)setType:(NSString *)type{
    _label.text = type;
}
- (void)setStarCount:(NSNumber *)starCount{
    _scoreLabel.text = [NSString stringWithFormat:@"%.1f",[starCount integerValue] / 2.0];
    if ([_scoreLabel.text isEqualToString:@"0.0"]) {
        _scoreLabel.hidden = YES;
    } else {
        _scoreLabel.hidden = NO;
    }
    NSInteger count = [starCount integerValue];
    NSInteger allStar = count / 2;
    NSInteger halfStar = count % 2;
    for (int i = 0; i < 5; i++) {
        UIImageView *imageV = [self viewWithTag:20 + i];
        imageV.image = [UIImage imageNamed:@"星1-2@3x"];
        if (i < allStar) {
            imageV.image = [UIImage imageNamed:@"星-1@3x"];
        }
    }
    if (halfStar) {
        UIImageView *imageV = [self viewWithTag:20 + allStar];
        imageV.image = [UIImage imageNamed:@"星-3@3x"];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
